package com.msg.test01;

import java.sql.*;

/**
 * @author wuJiaWei
 * @version 1.0
 */
public class Test02 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取连接
        String url="jdbc:mysql://127.0.0.1:3306/msb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        String username = "root";
        String password = "123456";
        Connection conn = DriverManager.getConnection(url, username, password);
        //创建会话
        Statement stmt = conn.createStatement();
        //执行sql
        //发送SQL:RestSet结果集合 - 结果集
        ResultSet rs = stmt.executeQuery("select * from t_book");
        //处理结果集
        while (rs.next()){//判断是否有记录存在
            System.out.println(rs.getInt("id")+" "+rs.getString("name")+" "+rs.getString("author")+" "+rs.getDouble("price"));
        }
//        1 活着 余华 45.0
//        2 红高粱 莫言 46.0
//        3 java 张三 1.0
    }
}
